import fitz

image_path = "PacManGrid.png"


# doc = fitz.Document(file)

def insert_image_into_pdf(image_path, output_pdf_path):
    # 创建一个新的PDF文档
    doc = fitz.Document()
    t = 2
    if t == 1:
        # 添加一个空白页面
        page = doc.new_page()  # 默认参数创建一页A4纸大小的空白页

        # 插入图片
        rect = page.rect  # 获取页面的矩形区域
        page.insert_image(rect, filename=image_path)
    else:
        doc.insert_file(image_path)
    doc.save(output_pdf_path)
    doc.close()


# 调用函数
output_pdf_path = "output.pdf"  # 输出的PDF文件名
insert_image_into_pdf(image_path, output_pdf_path)
